package com.wm.mvp.base

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import butterknife.ButterKnife
import com.blankj.utilcode.util.BusUtils
import com.bytedance.scene.ui.template.AppCompatScene
import com.wm.mvp.BaseModel
import com.wm.mvp.BaseMvp
import com.wm.mvp.BasePresenter
import com.wm.mvp.BaseView

abstract class BaseScene<M:BaseModel,V:BaseView,P:BasePresenter<M,V>>:AppCompatScene(),BaseMvp<M,V,P> {
    var presenter:P? = null
    override fun onCreateContentView(
        inflater: LayoutInflater,
        container: ViewGroup,
        savedInstanceState: Bundle?
    ): View? {
        var view = inflater.inflate(getLayoutId(),container,false)
        presenter = createPresenter()
        presenter?.registerModel(createMode())
        presenter?.registerView(createView())
        return view
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        BusUtils.register(this)
        ButterKnife.bind(this,view)
        initView(view)
        initData()
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        //打开右滑返回
        setSwipeEnabled(true)
        //去标题栏
        setToolbarVisible(false)
    }

    /**
     * 获取布局ID
     */
    abstract fun getLayoutId():Int

    /**
     * 初始化控件
     */
    abstract fun initView(v:View)

    /**
     * 初始化数据
     */
    abstract fun initData()


    override fun onDestroyView() {
        super.onDestroyView()
        BusUtils.unregister(this)
    }
}